<?php

class Back_ConfigController extends Osml_Controller_Admin_Action
{

    public function indexAction ()
    {
        $model = new Back_Model_Config();
        $select = new Zend_Db_Table_Select($model->_getMapper()->_getTable());
        
        $form = null;
        
        $this->view->tableIdField = 'nom';
        $this->view->tableSelect = $select;
        $this->view->tableHeader = array(
                'nom' => array(
                        'name' => 'nom',
                        'link' => array(
                                'action' => 'editer'
                        )
                ),
                'valeur' => array(
                        'name' => __("Valeur"),
                        'link' => array(
                                'action' => 'editer'
                        )
                ),
                'description' => array(
                        'name' => __("Description"),
                        'link' => array(
                                'action' => 'editer'
                        )
                )
        );
        
        /*
         * Thierry BROUARD (BIIS) callback = array( $objet, $method ) link =
         * array( action [,controller[,module]] ) ou array( 'callback' => array(
         * $objet, $method ) )
         */
        $this->view->tableOptions = array(
                'callback' => array(
                        $this,
                        '_transformRowsCallback'
                ), // Transformation callback
                'link' => array(
                        'action' => 'voir',
                        'clePrimaire' => 'nom'
                ),
                'pageNumber' => (int) $this->_getParam('page', 1),
                'pageItemPerPage' => (int) $this->_getParam('par', 10),
                'form' => $form
        );
    }
    
    public function indextypecontactAction ()
    {
        $model = new Back_Model_TypeContact();
        $select = new Zend_Db_Table_Select($model->_getMapper()->_getTable());
        
        $form = null;
        
        $this->view->tableIdField = 'id_type_contact';
        $this->view->tableSelect = $select;
        $this->view->tableHeader = array(
                'nom' => array(
                        'name' => 'nom',
                        'link' => array(
                                'action' => 'editertypecontact'
                        )
                ),
                'mode_envoie' => array(
                        'name' => __("Type"),
                        'link' => array(
                                'action' => 'editertypecontact'
                        )
                ),
                'a_contacter' => array(
                        'name' => __("Destinataire"),
                        'link' => array(
                                'action' => 'editertypecontact'
                        )
                )
        );
        
        /*
         * Thierry BROUARD (BIIS) callback = array( $objet, $method ) link =
         * array( action [,controller[,module]] ) ou array( 'callback' => array(
         * $objet, $method ) )
         */
        $this->view->tableOptions = array(
                'callback' => array(
                        $this,
                        '_transformRowsCallback'
                ), // Transformation callback
                'link' => array(
                        'action' => 'voir',
                ),
                'pageNumber' => (int) $this->_getParam('page', 1),
                'pageItemPerPage' => (int) $this->_getParam('par', 10),
                'form' => $form
        );
    }

    public function editerAction ()
    {
        $requete = $this->getRequest();
        $id = $requete->getParam("nom", "");
        
        $model = new Back_Model_Config();
        if ($id != "") {
            $model->charger($id);
        }
        
        $form = new Back_Form_Config();
        if ($requete->isPost()) {
            if ($form->isValid($requete->getPost())) {
                $model->setOptions($form->getValues());
                $model->setId($model->getNom());
                $resultat = $model->sauver();
                
                return $this->_helper->redirector('index');
            }
        } elseif ($requete->isGet()) {
            if ($id != "") {
                $form->populate($model->toArray());
            }
        }
        $this->view->form = $form;
        $this->view->model = $model;
    }

    public function supprimerAction ()
    {
        throw new Zend_Exception(
                __("La suppression n'est pas autorisée pour cette table."));
    }

    /**
     *
     * @see Jnd_Controller_Action::_transformRowsCallback()
     */
    public function _transformRowsCallback ($row, $view)
    {}

    public function analyseAction ()
    {
        $this->desactivationRendu();
        $acl = new Osml_Acl();
    }
    
    public function editertypecontactAction() {
        $requete = $this->getRequest();
        $id = $requete->getParam("id", 0);
        
        $model = new Back_Model_TypeContact();
        if ($id != "") {
            $model->charger($id);
        }
        
        $form = new Back_Form_TypeContact();
        if ($requete->isPost()) {
            if ($form->isValid($requete->getPost())) {
                $model->setOptions($form->getValues());
                $resultat = $model->sauver();
        
                return $this->redirect("indextypecontact");
            }
        } elseif ($requete->isGet()) {
            if ($id != "") {
                $form->populate($model->toArray());
            }
        }
        $this->view->form = $form;
        $this->view->model = $model;
    }
}

